import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
import 'package:fluwx/fluwx.dart';
import 'package:get/get.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/config/config.dart';

import '../../helper.dart';
import '../../router.dart';
import 'logic.dart';
import 'state.dart';

class InviteKocPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return _InviteKocPage();
  }
}

class _InviteKocPage extends State<InviteKocPage> {
  final InviteKocLogic logic = Get.put(InviteKocLogic());
  final InviteKocState state = Get.find<InviteKocLogic>().state;
  GlobalKey repaintWidgetKey = GlobalKey();

  Future<bool> requestLocationPermission() async {
    //获取当前的权限
    var status = await Permission.storage.status;
    if (status == PermissionStatus.granted) {
      //已经授权
      return true;
    } else {
      //如果客户拒绝过一次，则不再申请权限
      if (SpUtil.getBool('Permissionstoragestatus')==true )
      {
        toast('请在手机设置中授予存储访问权限');
        return false;
      }
      //未授权则发起一次申请
      status = await Permission.storage.request();
      if (status == PermissionStatus.granted) {
        return true;
      } else {
        SpUtil.putBool('Permissionstoragestatus',true);
        return false;
      }
    }
  }

  String name = SpUtil.getString('empeName') ?? '';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Config.mainColor,
        brightness: Brightness.light,
        iconTheme: IconThemeData(color: Colors.white),
        title: Text(
          "邀请推广会员",
          style: TextStyle(color: Colors.white, fontSize: 32.sp),
        ),
        centerTitle: true,
        elevation: 0,
        actions: [
          GestureDetector(
            onTap: () {
              Get.toNamed(RouteConfig.myInvite);
            },
            child: Padding(
              padding: EdgeInsets.symmetric(
                horizontal: 30.w,
                vertical: 5.w,
              ),
              child: Center(
                child: Text(
                  "我的邀请",
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 28.sp,
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
      body: GetBuilder<InviteKocLogic>(
        builder: (logic) {
          // String color = state.color;
          // color = color.replaceAll("rgba(", "");
          // color = color.replaceAll(")", ""); // 237, 241, 5, 0.02
          // List colorList = List.from(color.split(","));
          // print(colorList);
          // if (state.tpl == 1) {
          //   return _buildWidget1(colorList);
          // }
          // if (state.tpl == 2) {
          //   return _buildWidget2(colorList);
          // }
          // if (state.tpl == 3) {
          //   return _buildWidget3(colorList);
          // }
          // if (state.tpl == 4) {
          //   return _buildWidget4(colorList);
          // }
          // return _buildWidget1(colorList);
          return _buildKOCWidget();
        },
      ),
    );
  }

  Widget _buildWidget2(List<dynamic> colorList) {
    return Container(
      width: 750.w,
      padding: EdgeInsets.only(
        top: 62.w,
        left: 80.w,
      ),
      child: Stack(
        children: [
          Column(
            children: [
              state.imgUrl == ""
                  ? Container()
                  : RepaintBoundary(
                      key: repaintWidgetKey,
                      child: GestureDetector(
                        onLongPress: () async {
                          BuildContext buildContext =
                              repaintWidgetKey.currentContext;
                          if (null != buildContext) {
                            if (state.phone == '' || state.phone == null) {
                              toast('招募KOC需要维护好您的手机号，请确认已维护。');
                            } else {
                              bool hasLocationPermission =
                                  await requestLocationPermission();
                              if (hasLocationPermission) {
                                RenderRepaintBoundary boundary =
                                    buildContext.findRenderObject();
                                ui.Image image =
                                    await boundary.toImage(pixelRatio: 3.0);
                                ByteData byteData = await image.toByteData(
                                    format: ui.ImageByteFormat.png);
                                final result =
                                    await ImageGallerySaver.saveImage(
                                        byteData.buffer.asUint8List());
                                toast('保存成功');
                                print("定位权限申请通过");
                                var model = new WeChatShareMiniProgramModel(
                                  path:
                                      '/otherpage/pages/koc/createKOC?parentMobile=${state.phone}&mberType=2',
                                  webPageUrl: 'www.baidu.com',
                                  miniProgramType: WXMiniProgramType.RELEASE,
                                  //     userName: "gh_4XXXXXXXXX",//原始id 小程序的 看好 原始id 不是appid
                                  userName: Config.MINI_ACCOUNT,
                                  title: state.text,
                                  description: state.text,
                                  thumbnail:
                                      WeChatImage.network('${state.imgUrl}'),
                                );
                                fluwx.shareToWeChat(model);
                              } else {
                                print("定位权限申请不通过");
                              }
                            }
                          }
                        },
                        child: Container(
                          width: 590.w,
                          height: 890.w,
                          padding: EdgeInsets.symmetric(
                            horizontal: 30.w,
                            vertical: 50.w,
                          ),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(
                              Radius.circular(
                                20.w,
                              ),
                            ),
                            image: new DecorationImage(
                              fit: BoxFit.cover,
                              image: new NetworkImage(
                                state.imgUrl,
                              ),
                            ),
                          ),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.end,
                            children: [
                              Column(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  Container(
                                    padding: EdgeInsets.only(
                                      left: 30.w,
                                      right: 30.w,
                                      top: 180.w,
                                    ),
                                    child: Column(
                                      children: [
                                        ClipOval(
                                          child: Image.asset(
                                            "assets/images/avatar.png",
                                            width: 80.w,
                                            fit: BoxFit.cover,
                                          ),
                                        ),
                                        SizedBox(
                                          width: 10.w,
                                        ),
                                        Text(
                                          name,
                                          style: TextStyle(
                                            color: Color.fromRGBO(
                                                int.parse(colorList[0]),
                                                int.parse(colorList[1]),
                                                int.parse(colorList[2]),
                                                double.parse(colorList[3])),
                                            fontSize: 36.sp,
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                  SizedBox(
                                    height: 20.w,
                                  ),
                                  Container(
                                    width: 260.w,
                                    child: Text(
                                      state.text,
                                      textAlign: ui.TextAlign.center,
                                      style: TextStyle(
                                        color: Color.fromRGBO(
                                            int.parse(colorList[0]),
                                            int.parse(colorList[1]),
                                            int.parse(colorList[2]),
                                            double.parse(colorList[3])),
                                        fontSize: 26.sp,
                                      ),
                                      // color: Colors.white, fontSize: 30.w),
                                    ),
                                  ),
                                ],
                              ),
                              if (state.qrCode.isNotEmpty)
                                Container(
                                  child: Image.network(
                                    state.qrCode,
                                    width: 180.w,
                                    height: 180.w,
                                  ),
                                ),
                            ],
                          ),
                        ),
                      ),
                    ),
              SizedBox(
                height: 44.w,
              ),
              Text("长按图片保存相册并分享"),
            ],
          ),
          Positioned(
            bottom: 100.w,
            child: GestureDetector(
              onTap: () {
                var model = new WeChatShareMiniProgramModel(
                  path:
                      '/otherpage/pages/koc/createKOC?parentMobile=${state.phone}&mberType=2',
                  webPageUrl: 'www.baidu.com',
                  miniProgramType: WXMiniProgramType.RELEASE,
                  //     userName: "gh_4XXXXXXXXX",//原始id 小程序的 看好 原始id 不是appid
                  userName: Config.MINI_ACCOUNT,
                  title: state.text,
                  description: state.text,
                  thumbnail: WeChatImage.network('${state.imgUrl}'),
                );
                fluwx.shareToWeChat(model);
              },
              child: Container(
                margin: EdgeInsets.only(top: 80.w),
                child: Container(
                  width: 600.w,
                  height: 80.w,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(
                      Radius.circular(100),
                    ),
                    color: Config.mainColor,
                  ),
                  child: Center(
                    child: Text(
                      "分享好友",
                      style: TextStyle(
                        fontSize: 34.sp,
                        color: Color(0xffffffff),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _buildWidget4(List<dynamic> colorList) {
    return Container(
      width: 750.w,
      padding: EdgeInsets.only(
        top: 62.w,
        left: 80.w,
      ),
      child: Stack(
        children: [
          Column(
            children: [
              state.imgUrl == ""
                  ? Container()
                  : RepaintBoundary(
                      key: repaintWidgetKey,
                      child: GestureDetector(
                        onLongPress: () async {
                          BuildContext buildContext =
                              repaintWidgetKey.currentContext;
                          if (null != buildContext) {
                            if (state.phone == '' || state.phone == null) {
                              toast('招募KOC需要维护好您的手机号，请确认已维护。');
                            } else {
                              bool hasLocationPermission =
                                  await requestLocationPermission();
                              if (hasLocationPermission) {
                                RenderRepaintBoundary boundary =
                                    buildContext.findRenderObject();
                                ui.Image image =
                                    await boundary.toImage(pixelRatio: 3.0);
                                ByteData byteData = await image.toByteData(
                                    format: ui.ImageByteFormat.png);
                                final result =
                                    await ImageGallerySaver.saveImage(
                                        byteData.buffer.asUint8List());
                                toast('保存成功');
                                print("定位权限申请通过");
                                var model = new WeChatShareMiniProgramModel(
                                  path:
                                      '/otherpage/pages/koc/createKOC?parentMobile=${state.phone}&mberType=2',
                                  webPageUrl: 'www.baidu.com',
                                  miniProgramType: WXMiniProgramType.RELEASE,
                                  //     userName: "gh_4XXXXXXXXX",//原始id 小程序的 看好 原始id 不是appid
                                  userName: Config.MINI_ACCOUNT,
                                  title: state.text,
                                  description: state.text,
                                  thumbnail:
                                      WeChatImage.network('${state.imgUrl}'),
                                );
                                fluwx.shareToWeChat(model);
                              } else {
                                print("定位权限申请不通过");
                              }
                            }
                          }
                        },
                        child: Container(
                          width: 590.w,
                          height: 890.w,
                          padding: EdgeInsets.symmetric(
                            horizontal: 30.w,
                            vertical: 50.w,
                          ),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(
                              Radius.circular(
                                20.w,
                              ),
                            ),
                            image: new DecorationImage(
                              fit: BoxFit.cover,
                              image: new NetworkImage(
                                state.imgUrl,
                              ),
                            ),
                          ),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.end,
                            children: [
                              if (state.qrCode.isNotEmpty)
                                Container(
                                  child: Image.network(
                                    state.qrCode,
                                    width: 180.w,
                                    height: 180.w,
                                  ),
                                ),
                              Column(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  Container(
                                    padding: EdgeInsets.only(
                                      left: 30.w,
                                      right: 30.w,
                                      top: 180.w,
                                    ),
                                    child: Column(
                                      children: [
                                        ClipOval(
                                          child: Image.asset(
                                            "assets/images/avatar.png",
                                            width: 80.w,
                                            fit: BoxFit.cover,
                                          ),
                                        ),
                                        SizedBox(
                                          width: 10.w,
                                        ),
                                        Text(
                                          name,
                                          style: TextStyle(
                                            color: Color.fromRGBO(
                                                int.parse(colorList[0]),
                                                int.parse(colorList[1]),
                                                int.parse(colorList[2]),
                                                double.parse(colorList[3])),
                                            fontSize: 36.sp,
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                  SizedBox(
                                    height: 20.w,
                                  ),
                                  Container(
                                    width: 260.w,
                                    child: Text(
                                      state.text,
                                      textAlign: ui.TextAlign.center,
                                      style: TextStyle(
                                        color: Color.fromRGBO(
                                            int.parse(colorList[0]),
                                            int.parse(colorList[1]),
                                            int.parse(colorList[2]),
                                            double.parse(colorList[3])),
                                        fontSize: 26.sp,
                                      ),
                                      // color: Colors.white, fontSize: 30.w),
                                    ),
                                  ),
                                ],
                              )
                            ],
                          ),
                        ),
                      ),
                    ),
              SizedBox(
                height: 44.w,
              ),
              Text("长按图片保存相册并分享"),
            ],
          ),
          Positioned(
            bottom: 100.w,
            child: GestureDetector(
              onTap: () {
                var model = new WeChatShareMiniProgramModel(
                  path:
                      '/otherpage/pages/koc/createKOC?parentMobile=${state.phone}&mberType=2',
                  webPageUrl: 'www.baidu.com',
                  miniProgramType: WXMiniProgramType.RELEASE,
                  //     userName: "gh_4XXXXXXXXX",//原始id 小程序的 看好 原始id 不是appid
                  userName: Config.MINI_ACCOUNT,
                  title: state.text,
                  description: state.text,
                  thumbnail: WeChatImage.network('${state.imgUrl}'),
                );
                fluwx.shareToWeChat(model);
              },
              child: Container(
                margin: EdgeInsets.only(top: 80.w),
                child: Container(
                  width: 600.w,
                  height: 80.w,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(
                      Radius.circular(100),
                    ),
                    color: Config.mainColor,
                  ),
                  child: Center(
                    child: Text(
                      "分享好友",
                      style: TextStyle(
                        fontSize: 34.sp,
                        color: Color(0xffffffff),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _buildWidget1(List<dynamic> colorList) {
    return Container(
      width: 750.w,
      padding: EdgeInsets.only(
        top: 62.w,
        left: 80.w,
      ),
      child: Stack(
        children: [
          Column(
            children: [
              state.imgUrl == ""
                  ? Container()
                  : RepaintBoundary(
                      key: repaintWidgetKey,
                      child: GestureDetector(
                        onLongPress: () async {
                          BuildContext buildContext =
                              repaintWidgetKey.currentContext;
                          if (null != buildContext) {
                            if (state.phone == '' || state.phone == null) {
                              toast('招募KOC需要维护好您的手机号，请确认已维护。');
                            } else {
                              bool hasLocationPermission =
                                  await requestLocationPermission();
                              if (hasLocationPermission) {
                                RenderRepaintBoundary boundary =
                                    buildContext.findRenderObject();
                                ui.Image image =
                                    await boundary.toImage(pixelRatio: 3.0);
                                ByteData byteData = await image.toByteData(
                                    format: ui.ImageByteFormat.png);
                                final result =
                                    await ImageGallerySaver.saveImage(
                                        byteData.buffer.asUint8List());
                                toast('保存成功');
                                print("定位权限申请通过");
                                var model = new WeChatShareMiniProgramModel(
                                  path:
                                      '/otherpage/pages/koc/createKOC?parentMobile=${state.phone}&mberType=2',
                                  webPageUrl: 'www.baidu.com',
                                  miniProgramType: WXMiniProgramType.RELEASE,
                                  //     userName: "gh_4XXXXXXXXX",//原始id 小程序的 看好 原始id 不是appid
                                  userName: Config.MINI_ACCOUNT,
                                  title: state.text,
                                  description: state.text,
                                  thumbnail:
                                      WeChatImage.network('${state.imgUrl}'),
                                );
                                fluwx.shareToWeChat(model);
                              } else {
                                print("定位权限申请不通过");
                              }
                            }
                          }
                        },
                        child: Container(
                          width: 590.w,
                          height: 890.w,
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(
                              Radius.circular(
                                20.w,
                              ),
                            ),
                            image: new DecorationImage(
                              fit: BoxFit.cover,
                              image: new NetworkImage(
                                state.imgUrl,
                              ),
                            ),
                          ),
                          child: Column(
                            children: [
                              Container(
                                padding: EdgeInsets.only(
                                  left: 30.w,
                                  right: 30.w,
                                  top: 180.w,
                                ),
                                child: Row(
                                  children: [
                                    ClipOval(
                                      child: Image.asset(
                                        "assets/images/avatar.png",
                                        width: 80.w,
                                        fit: BoxFit.cover,
                                      ),
                                    ),
                                    SizedBox(
                                      width: 10.w,
                                    ),
                                    Text(
                                      name,
                                      style: TextStyle(
                                        color: Color.fromRGBO(
                                            int.parse(colorList[0]),
                                            int.parse(colorList[1]),
                                            int.parse(colorList[2]),
                                            double.parse(colorList[3])),
                                        fontSize: 36.sp,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              SizedBox(
                                height: 30.w,
                              ),
                              Container(
                                child: Text(
                                  state.text,
                                  style: TextStyle(
                                      color: Color.fromRGBO(
                                          int.parse(colorList[0]),
                                          int.parse(colorList[1]),
                                          int.parse(colorList[2]),
                                          double.parse(colorList[3])),
                                      fontSize: 30.w),
                                  // color: Colors.white, fontSize: 30.w),
                                ),
                              ),
                              SizedBox(
                                height: 210.w,
                              ),
                              if (state.qrCode.isNotEmpty)
                                Container(
                                  child: Image.network(
                                    state.qrCode,
                                    width: 250.w,
                                    height: 250.w,
                                  ),
                                ),
                            ],
                          ),
                        ),
                      ),
                    ),
              SizedBox(
                height: 44.w,
              ),
              Text("长按图片保存相册并分享"),
            ],
          ),
          Positioned(
            bottom: 100.w,
            child: GestureDetector(
              onTap: () {
                var model = new WeChatShareMiniProgramModel(
                  path:
                      '/otherpage/pages/koc/createKOC?parentMobile=${state.phone}&mberType=2',
                  webPageUrl: 'www.baidu.com',
                  miniProgramType: WXMiniProgramType.RELEASE,
                  //     userName: "gh_4XXXXXXXXX",//原始id 小程序的 看好 原始id 不是appid
                  userName: Config.MINI_ACCOUNT,
                  title: state.text,
                  description: state.text,
                  thumbnail: WeChatImage.network('${state.imgUrl}'),
                );
                fluwx.shareToWeChat(model);
              },
              child: Container(
                margin: EdgeInsets.only(top: 80.w),
                child: Container(
                  width: 600.w,
                  height: 80.w,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(
                      Radius.circular(100),
                    ),
                    color: Config.mainColor,
                  ),
                  child: Center(
                    child: Text(
                      "分享好友",
                      style: TextStyle(
                        fontSize: 34.sp,
                        color: Color(0xffffffff),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _buildWidget3(List<dynamic> colorList) {
    return Container(
      width: 750.w,
      padding: EdgeInsets.only(
        top: 62.w,
        left: 80.w,
      ),
      child: Stack(
        children: [
          Column(
            children: [
              state.imgUrl == ""
                  ? Container()
                  : RepaintBoundary(
                      key: repaintWidgetKey,
                      child: GestureDetector(
                        onLongPress: () async {
                          BuildContext buildContext =
                              repaintWidgetKey.currentContext;
                          if (null != buildContext) {
                            if (state.phone == '' || state.phone == null) {
                              toast('招募KOC需要维护好您的手机号，请确认已维护。');
                            } else {
                              bool hasLocationPermission =
                                  await requestLocationPermission();
                              if (hasLocationPermission) {
                                RenderRepaintBoundary boundary =
                                    buildContext.findRenderObject();
                                ui.Image image =
                                    await boundary.toImage(pixelRatio: 3.0);
                                ByteData byteData = await image.toByteData(
                                    format: ui.ImageByteFormat.png);
                                final result =
                                    await ImageGallerySaver.saveImage(
                                        byteData.buffer.asUint8List());
                                toast('保存成功');
                                print("定位权限申请通过");
                                var model = new WeChatShareMiniProgramModel(
                                  path:
                                      '/otherpage/pages/koc/createKOC?parentMobile=${state.phone}&mberType=2',
                                  webPageUrl: 'www.baidu.com',
                                  miniProgramType: WXMiniProgramType.RELEASE,
                                  //     userName: "gh_4XXXXXXXXX",//原始id 小程序的 看好 原始id 不是appid
                                  userName: Config.MINI_ACCOUNT,
                                  title: state.text,
                                  description: state.text,
                                  thumbnail:
                                      WeChatImage.network('${state.imgUrl}'),
                                );
                                fluwx.shareToWeChat(model);
                              } else {
                                print("定位权限申请不通过");
                              }
                            }
                          }
                        },
                        child: Container(
                          width: 590.w,
                          height: 890.w,
                          padding: EdgeInsets.symmetric(
                            horizontal: 40.w,
                            vertical: 50.w,
                          ),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(
                              Radius.circular(
                                20.w,
                              ),
                            ),
                            image: new DecorationImage(
                              fit: BoxFit.cover,
                              image: new NetworkImage(
                                state.imgUrl,
                              ),
                            ),
                          ),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.end,
                            children: [
                              Container(
                                padding: EdgeInsets.only(
                                  left: 30.w,
                                  right: 30.w,
                                  top: 180.w,
                                ),
                                child: Column(
                                  children: [
                                    ClipOval(
                                      child: Image.asset(
                                        "assets/images/avatar.png",
                                        width: 80.w,
                                        fit: BoxFit.cover,
                                      ),
                                    ),
                                    SizedBox(
                                      width: 10.w,
                                    ),
                                    Text(
                                      name,
                                      style: TextStyle(
                                        color: Color.fromRGBO(
                                            int.parse(colorList[0]),
                                            int.parse(colorList[1]),
                                            int.parse(colorList[2]),
                                            double.parse(colorList[3])),
                                        fontSize: 36.sp,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              SizedBox(
                                height: 20.w,
                              ),
                              Container(
                                child: Text(
                                  state.text,
                                  style: TextStyle(
                                      color: Color.fromRGBO(
                                          int.parse(colorList[0]),
                                          int.parse(colorList[1]),
                                          int.parse(colorList[2]),
                                          double.parse(colorList[3])),
                                      fontSize: 26.sp),
                                  // color: Colors.white, fontSize: 30.w),
                                ),
                              ),
                              SizedBox(
                                height: 210.w,
                              ),
                              if (state.qrCode.isNotEmpty)
                                Align(
                                  alignment: Alignment.centerRight,
                                  child: Container(
                                    child: Image.network(
                                      state.qrCode,
                                      width: 180.w,
                                      height: 180.w,
                                    ),
                                  ),
                                ),
                            ],
                          ),
                        ),
                      ),
                    ),
              SizedBox(
                height: 44.w,
              ),
              Text("长按图片保存相册并分享"),
            ],
          ),
          Positioned(
            bottom: 100.w,
            child: GestureDetector(
              onTap: () {
                var model = new WeChatShareMiniProgramModel(
                  path:
                      '/otherpage/pages/koc/createKOC?parentMobile=${state.phone}&mberType=2',
                  webPageUrl: 'www.baidu.com',
                  miniProgramType: WXMiniProgramType.RELEASE,
                  //     userName: "gh_4XXXXXXXXX",//原始id 小程序的 看好 原始id 不是appid
                  userName: Config.MINI_ACCOUNT,
                  title: state.text,
                  description: state.text,
                  thumbnail: WeChatImage.network('${state.imgUrl}'),
                );
                fluwx.shareToWeChat(model);
              },
              child: Container(
                margin: EdgeInsets.only(top: 80.w),
                child: Container(
                  width: 600.w,
                  height: 80.w,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(
                      Radius.circular(100),
                    ),
                    color: Config.mainColor,
                  ),
                  child: Center(
                    child: Text(
                      "分享好友",
                      style: TextStyle(
                        fontSize: 34.sp,
                        color: Color(0xffffffff),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _buildKOCWidget() {
    return Container(
      width: 750.w,
      child: Stack(
        children: [
          Column(
            children: [
              RepaintBoundary(
                key: repaintWidgetKey,
                child: GestureDetector(
                  onLongPress: () async {
                    BuildContext buildContext =
                        repaintWidgetKey.currentContext;
                    if (null != buildContext) {
                      if (state.phone == '' || state.phone == null) {
                        toast('招募会员需要维护好您的手机号，请确认已维护。');
                      } else {
                        bool hasLocationPermission =
                        await requestLocationPermission();
                        if (hasLocationPermission) {
                          RenderRepaintBoundary boundary =
                          buildContext.findRenderObject();
                          ui.Image image =
                          await boundary.toImage(pixelRatio: 3.0);
                          ByteData byteData = await image.toByteData(
                              format: ui.ImageByteFormat.png);
                          final result =
                          await ImageGallerySaver.saveImage(
                              byteData.buffer.asUint8List());
                          toast('保存成功');
                          print("定位权限申请通过");
                          // var model = new WeChatShareMiniProgramModel(
                          //   path: logic.miniPath,
                          //   webPageUrl: 'www.baidu.com',
                          //   miniProgramType: WXMiniProgramType.RELEASE,
                          //   //     userName: "gh_4XXXXXXXXX",//原始id 小程序的 看好 原始id 不是appid
                          //   userName: Config.MINI_ACCOUNT,
                          //   title: state.text,
                          //   description: state.text,
                          //   thumbnail: WeChatImage.asset(state.imgUrl)
                          //   // WeChatImage.network('${state.imgUrl}'),
                          // );
                          // fluwx.shareToWeChat(model);
                        } else {
                          print("定位权限申请不通过");
                        }
                      }
                    }
                  },
                  child: Container(
                    width: double.infinity,
                    height: 650,
                    child: Stack(
                      alignment: Alignment.center,
                      children: [
                        Positioned(
                            top: 0,
                            child: Image.asset(state.imgUrl, width: ScreenUtil().screenWidth,fit: BoxFit.fitWidth,)
                        ),
                        Positioned(
                          bottom: 150,
                          child: Column(
                            children: [
                              if (state.qrCode.isNotEmpty)
                                Container(
                                  child: Image.network(
                                    state.qrCode,
                                    width: 250.w,
                                    height: 250.w,
                                  )
                                )
                            ],
                          ),
                        ),
                        Positioned(child: Text("长按图片保存到相册", style: TextStyle(color: Colors.grey ),),
                          bottom: 80,),
                      ],
                    )
                  ),
                ),
              )
            ],
          ),
          Positioned(
            bottom: 60.w,
            child: GestureDetector(
              onTap: () {
                var model = new WeChatShareMiniProgramModel(
                  path: logic.miniPath,
                  webPageUrl: 'www.baidu.com',
                  miniProgramType: WXMiniProgramType.RELEASE,
                  //     userName: "gh_4XXXXXXXXX",//原始id 小程序的 看好 原始id 不是appid
                  userName: Config.MINI_ACCOUNT,
                  title: state.text,
                  description: state.text,
                  thumbnail: WeChatImage.asset('${state.imgUrl}'),
                );
                fluwx.shareToWeChat(model);
              },
              child: Container(
                alignment: Alignment.center,
                width: ScreenUtil().screenWidth,
                margin: EdgeInsets.only(top: 80.w),
                child: Container(
                  width: 600.w,
                  height: 80.w,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(
                      Radius.circular(100),
                    ),
                    color: Config.mainColor,
                  ),
                  child: Center(
                    child: Text(
                      "分享给好友",
                      style: TextStyle(
                        fontSize: 34.sp,
                        color: Color(0xffffffff),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
